package com.heo.coder.packet;

import com.heo.coder.packet.base.BasePacket;
import com.heo.util.ByteHelper;
import com.heo.util.Utils;

public class EndPacketRsp extends BasePacket{

	public EndPacketRsp(String head, String id, int bodyLength, String msta,
			String control, String body, String check) throws Exception {
		super(head, id, bodyLength, msta, control, body, check);
	}
	
	/**
	 * 
	 * @param passageway  通道号
	 * @param userMobile  手机号
	 */
	public void setMsgContent(int passageway, String flowNumberStr, String userMobile) {
		setBodyLengthStr(ByteHelper.strReversal(ByteHelper.intToHexString(21, 4)));
		StringBuilder sBuilder = new StringBuilder();
		String passagewayStr = ByteHelper.intToHexString(passageway, 2);
		userMobile = "0" + userMobile;
		String userMobileStr = ByteHelper.stringToAscii(userMobile);
		String checkCode = ByteHelper.stringToAscii(flowNumberStr.substring(flowNumberStr.length() - 4, flowNumberStr.length()));
		System.out.println(checkCode);
		String timeCode = ByteHelper.intToHexString(Utils.getInteger(flowNumberStr), 8);
		timeCode = ByteHelper.strReversal(timeCode.toUpperCase());
		sBuilder.append(timeCode).append(passagewayStr).append(userMobileStr).append(checkCode);
		setBody(sBuilder.toString());
		String check = ByteHelper.makeCheckSum(START_MARKER_LENGTH_CODE + getHead() + getMsta() + getId() + START_MARKER_LENGTH_CODE + getControl() + getBodyLengthStr() + getBody());
		setCheck(check);
	}
	
	@Override
	public String toString() {
		return "SocketPacket: [" + control + "] [" + START_MARKER_LENGTH_CODE + getHead() + getMsta() + getId() + START_MARKER_LENGTH_CODE + getControl() +  getBodyLengthStr() + getBody() + getCheck() + END_MARKER_LENGTH_CODE + "]";
	}

	@Override
	public String getPacketBody() {
		return super.body;
	}

	
	
}
